#include <cstdio>
#include <algorithm>

struct Stu {
    int grade;
    int time;
    int id;
} stus[110];


/**
 * 
 * 时间复杂度：O(n+q)
 * 空间复杂度：O(n)
 * 
 * 排序
 * @return
 */
int main() {
    int n;
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        int grade, time, id;
        scanf("%d %d %d", &grade, &time, &id);
        stus[i] = { grade, time, id };

    }

    int q;
    scanf("%d", &q);

    for (int i = 0; i < q; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        std::swap(stus[x - 1], stus[y - 1]);
    }

    for (int i = 0; i < n; i++) {
        printf("%d %d %d\n", stus[i].grade, stus[i].time, stus[i].id);
    }

    return 0;
}